import pandas as pd
import numpy as np
from datetime import datetime, timedelta
import sys
import random

output_size = 1000

if len(sys.argv) > 1:
    output_size = int(sys.argv[1])


# 设置随机种子以确保结果可复现
np.random.seed(42)
random.seed(42)

# 定义数据
all_ids = [f"V{str(i).zfill(4)}" for i in range(1, output_size + 1)]
all_authors = ["搞笑小达人", "沙雕网友", "段子手联盟", "神回复bot", "翻车现场", "恶搞大师", "影视吐槽君", "综艺挖掘机", "游戏解说员", "剧情解说家", "反转女王", "爽剧推荐官", "萌宠搞笑君", "美食翻车王", "评论大赏", "挑战达人", "配音鬼才", "吐槽小能手", "游戏萌新开", "反转制造机"]
all_labels='搞笑,沙雕,段子,神回复,翻车现场,恶搞,影视吐槽,综艺吐槽,游戏解说,剧情解说,反转,爽剧,霸总,甜宠,悬疑,穿越,翻唱,洗脑神曲,舞蹈挑战,手势舞,热点追踪,明星同款,吃瓜第一线,高燃混剪,CP混剪,名场面,二次元,手书,AMV,MAD,高能时刻,搞笑击杀,沙雕MOD,彩蛋,萌宠,萌娃,奇葩美食,街头实验,治愈,解压,泪目,高燃,社死,尴尬癌,全程姨母笑,宿舍日常,打工日记,老板来了,闺蜜,男友视角,熊孩子,短视频,竖屏剧场,一口气看完,3分钟系列,挑战,合拍,duet,react,投票,今日热点,520,毕业季,世界杯,跨年,春节档,上热门,宝藏博主,关注我,FPS,MOBA,休闲小游戏,韩剧,美剧,国产剧,经典港片,猫,狗,仓鼠,异宠,广告,植入,联名,开箱测评,直播带货'.split(',')
all_categories = '搞笑合集,沙雕日常,经典段子,神回复现场,翻车现场,恶搞系列,影视吐槽,综艺吐槽,游戏解说,剧情解说,反转神剧,爽剧推荐,沙雕挑战,搞笑配音,段子合集,神评论大赏,翻车合集,恶搞实验,综艺名场面,游戏翻车,剧情反转,爽文短剧,搞笑萌宠,沙雕网友,段子手合集,恶搞挑战,搞笑日常,沙雕操作,神评论合集,恶搞配音,爽剧解说'.split(',')


# 生成随机数据
data = []
start_date = datetime(2025, 1, 1)
end_date = datetime.now()

for i in range(output_size):
    # 1. 生成 video_id
    vid = all_ids[i]

    # 2-4.随机选择标题、描述和作者
    title = 'empty title' # random.choice(titles)
    category = random.choice(all_categories)
    author = 'user_' + str(vid) # random.choice(authors)

    # 5.随机生成发布时间, 从开始到截止日期间随机生成
    add_time = timedelta(seconds=random.randint(0, int((end_date - start_date).total_seconds())))
    publish_time = (start_date + add_time).strftime("%Y-%m-%d %H:%M:%S")
    
    # 6.随机生成长度（15-300秒）
    duration = random.randint(15_000, 300_000)
    
    # 7-9. 随机生成互动数据
    likes = random.randint(0, 1000)
    favorites = random.randint(0, 1000)
    reposts = random.randint(0, 1000)
    
    # 10. 生成标签
    labels = []
    label_count = random.randint(3, 8)
    for j in range(label_count):
        pos = random.randint(0, len(all_labels) - 1)
        # print(f'total: {len(all_labels)}, pos: {pos}')
        label = all_labels[pos]
        if not label in labels:
            labels.append(label)

    # 生成完成后添加到总数据列表中
    data.append({
        "vid": vid,
        "title": title,
        "category": category,
        "duration": duration,
        "author": author,
        "publish_time": publish_time,
        "likes": likes,
        "favorites": favorites,
        "reposts": reposts,
        "labels": ';'.join(labels)
    })

# 创建DataFrame
df = pd.DataFrame(data)

# 保存为CSV文件
csv_filename = "videos.csv"
df.to_csv(csv_filename, index=False, encoding='utf-8-sig')

# 显示前10条数据作为预览
print("数据生成完成！前10条数据预览：")
print(df.head(10))
print(f"\n数据已保存至：{csv_filename}")
print(f"共生成{output_size}条数据")